package cn.yueranzs.handler;

import cn.yueranzs.response.Result;
import cn.yueranzs.response.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 * @author yueranzs
 * @date 2021-11-01 11:55
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(BusinessException exception){
        log.error(exception.getErrMsg());
        return Result.error(exception.getCode(), exception.getErrMsg());
    }



}
